// 通用JS，定义成layui的模块
;layui.define(['layer'], function(exports) {
	var $ = layui.$,
		layer = layui.layer;
		
	exports('jwt', {
		ajax: function(cfg) {
			var me = this;	
			$.ajax({
		        type: 'post',
		        dataType: 'json',
		        url: cfg.url,
		        data: cfg.data || cfg.param || {},
		        async: (typeof cfg.async=='undefined') ? true : cfg.async,
		        success: cfg.success || cfg.callback,
		        error: cfg.error
		    });
		},
		// 读取cookie
		getCookie: function(name) {
			if (document.cookie.length > 0) {
	  			start = document.cookie.indexOf(name + "=");
	  			if (start!=-1) { 
	    			start = start + name.length + 1; 
	    			end = document.cookie.indexOf(";", start);
	    			if (end==-1) end = document.cookie.length;
	    			return unescape(document.cookie.substring(start, end));
	    		}
	  		}
			return "";
		},
		// 设置cookie
		setCookie: function(name, value) {
			var days = 30;
	    	var exp = new Date();
	    	exp.setTime(exp.getTime() + days*24*60*60*1000);
			document.cookie = name + "="+ escape(value) + ";path=/;expires=" + exp.toGMTString();
		}
	});
});

